/**
 * Created by asus on 2017/5/4. 曹中义
 */
require(["jquery", "template", "bbcare", "bootstrap3.min", "scprit/department/view/template/patientsWithHomeBaby-js.js"], function ($, template, $bb, bootstrap, tpl) {

    var URL = $bb.baseUrl("department") + "followup/service";
    var patientId = $bb.getPageParams();
    var rows = 5;
    //加载患者左侧详情
    $bb.ajax({
        url: URL + "/patient/patientDetailsQuery",
        type: "post",
        contentType: "application/json;charset=UTF-8",
        dataType: "json",
        data: JSON.stringify({
            data: {
                "userId": patientId
            }
        }),
        success: function (data) {
            tpl.FollowUpTitInit({"id": "patients", "data": data.data});
            var queueId = $("#queueId").val();
            //加载页面中间内容
            $bb.ajax({
                url: URL + "/patient/activeInfo/list",
                type: "post",
                contentType: "application/json;charset=UTF-8",
                dataType: "json",
                data: JSON.stringify({
                    data: {
                        "userId": patientId,
                        "queueId": queueId,
                        "rows": rows
                    }
                }),
                success: function (data) {
                    tpl.FollowUpTitInit1({"id": "type", "data": data});
                    var lastLine = $("#type").children("div:last-child").find(".timeLine");
                    lastLine.css("display", "none");
                    //温度和氧饱脉率详情查看
                    $(".temperature").click(function () {
                        $bb.openPage("physicalExaminationAnalysisReport", $(this).attr("id"))
                    })
                    $(".pulse").click(function () {
                        $bb.openPage("oxygenPulseFequency", $(this).attr("id"))
                    })
                    //按照不同分类刷新页面
                    $("#classification button").click(function () {
                        var busiCateGory = $(this).val();
                        console.log(busiCateGory);
                        $bb.ajax({
                            url: URL + "/patient/activeInfo/list",
                            type: "post",
                            contentType: "application/json;charset=UTF-8",
                            dataType: "json",
                            data: JSON.stringify({
                                data: {
                                    "userId": patientId,
                                    "queueId": queueId,
                                    "rows": rows,
                                    "busiCategory": busiCateGory
                                }
                            }),
                            success: function (data) {
                                tpl.FollowUpTitInit1({"id": "type", "data": data});
                                var lastLine = $("#type").children("div:last-child").find(".timeLine");
                                lastLine.css("display", "none");
                                $(".temperature").click(function () {
                                    $bb.openPage("physicalExaminationAnalysisReport", $(this).attr("id"))
                                })
                                $(".pulse").click(function () {
                                    $bb.openPage("oxygenPulseFequency", $(this).attr("id"))
                                })
                            },
                            error: function (data) {
                                console.log('请求出错' + data);
                            }
                        });
                    });
                    //根据队列类型刷新页面
                    $("#queueId").change(function () {
                        var queueId = $(this).val();
                        $bb.ajax({
                            url: URL + "/patient/activeInfo/list",
                            type: "post",
                            contentType: "application/json;charset=UTF-8",
                            dataType: "json",
                            data: JSON.stringify({
                                data: {
                                    "userId": patientId,
                                    "queueId": queueId,
                                    "rows": rows,
                                }
                            }),
                            success: function (data) {
                                tpl.FollowUpTitInit1({"id": "type", "data": data});
                                var lastLine = $("#type").children("div:last-child").find(".timeLine");
                                lastLine.css("display", "none");
                                $(".temperature").click(function () {
                                    $bb.openPage("physicalExaminationAnalysisReport", $(this).attr("id"))
                                })
                                $(".pulse").click(function () {
                                    $bb.openPage("oxygenPulseFequency", $(this).attr("id"))
                                })
                            },
                            error: function (data) {
                                console.log('请求出错' + data);
                            }
                        });
                    });
                    //点击加载更多
                    $("#more button").click(function () {
                        rows += 5;
                        $bb.ajax({
                            url: URL + "/patient/activeInfo/list",
                            type: "post",
                            contentType: "application/json;charset=UTF-8",
                            dataType: "json",
                            data: JSON.stringify({
                                data: {
                                    "userId": patientId,
                                    "queueId": queueId,
                                    "rows": rows,
                                }
                            }),
                            success: function (data) {
                                tpl.FollowUpTitInit1({"id": "type", "data": data});
                                var lastLine = $("#type").children("div:last-child").find(".timeLine");
                                lastLine.css("display", "none");
                                $(".temperature").click(function () {
                                    $bb.openPage("physicalExaminationAnalysisReport", $(this).attr("id"))
                                })
                                $(".pulse").click(function () {
                                    $bb.openPage("oxygenPulseFequency", $(this).attr("id"))
                                })
                            },
                            error: function (data) {
                                console.log('请求出错' + data);
                            }
                        });
                    });
                    //加载右侧医生图片
                    $bb.ajax({
                        url: URL + "/patient/activeInfo/doctorList",
                        type: "post",
                        contentType: "application/json;charset=UTF-8",
                        dataType: "json",
                        data: JSON.stringify({
                            data: {
                                "userId": patientId,
                                "queueId": queueId,
                            }
                        }),
                        success: function (data) {
                            tpl.FollowUpTitInit2({"id": "doctor", "data": data});

                        },
                        error: function (data) {
                            console.log('请求出错' + data);
                        }
                    });
                },
                error: function (data) {
                    console.log('请求出错' + data);
                }
            });
        },
        error: function (data) {
            console.log('请求出错' + data);
        }
    });
});
